package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.UserAccountDetail;
import com.atguigu.tingshu.vo.account.AccountLockResultVo;
import com.atguigu.tingshu.vo.account.AccountLockVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account/userAccount")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserAccountApiController {

    @Autowired
    private UserAccountService userAccountService;

    @GuiGuLogin
    @Operation(summary = "获取用户消费记录")
    @GetMapping("findUserConsumePage/{page}/{limit}")
    public Result<IPage<UserAccountDetail>> findUserConsumePage(@PathVariable("page") Long pageNo, @PathVariable("limit") Long pageSize){
        IPage<UserAccountDetail> page = userAccountService.findUserConsumePage(pageNo,pageSize);
        return Result.ok(page);
    }
    @GuiGuLogin
    @Operation(summary = "获取用户账户充值记录")
    @GetMapping("findUserRechargePage/{page}/{limit}")
    public Result<IPage<UserAccountDetail>> findUserRechargePage(@PathVariable("page") Long pageNo, @PathVariable("limit") Long pageSize){
        IPage<UserAccountDetail> userAccountDetail = userAccountService.findUserRechargePage(pageNo,pageSize);
        return Result.ok(userAccountDetail);
    }

    @GuiGuLogin
    @Operation(summary = "获取用户账户可用余额")
    @GetMapping("getAvailableAmount")
    public Result<BigDecimal> getAvailableAmount() {
        BigDecimal bigDecimal = userAccountService.getAvailableAmount();
        return Result.ok(bigDecimal);
    }

    @Operation(summary = "检查与锁定账户金额")
    @PostMapping("checkAndLock")
    public Result<AccountLockResultVo> checkAndLock(@RequestBody AccountLockVo accountLockVo) {
        AccountLockResultVo accountLockResultVo = userAccountService.checkAndLock(accountLockVo);
        return Result.ok(accountLockResultVo);
    }


}

